package com.walker.weixin.entity;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.apache.commons.collections4.MapUtils;

import java.io.Serializable;
import java.util.Map;

/**
 * @Description:  公众号消息父类
 * @ProjectName: wms_step
 * @Package: com.walker.weixin.entity
 * @ClassName: BaseMessage
 * @Author: yangyl
 * @CreateDate: 2020-07-20 15:49
 */
public abstract class BaseMessage implements Serializable {

    @XStreamAlias("ToUserName")
    private String toUserName;
    @XStreamAlias("FromUserName")
    private String fromUserName;
    @XStreamAlias("CreateTime")
    private String createTime;
    @XStreamAlias("MsgType")
    private String msgType;

    private static XStream xStream;

    private BaseMessage(){
        xStream = new XStream();
        xStream.autodetectAnnotations(true);
    }

    public BaseMessage(Map<String,Object> requestMap,String msgType){
        this();
        this.toUserName=MapUtils.getString(requestMap,"FromUserName");
        this.fromUserName=MapUtils.getString(requestMap,"ToUserName");
        this.createTime=String.valueOf(System.currentTimeMillis()/1000);
        this.msgType=msgType;

    }

    public String getToUserName() {
        return toUserName;
    }

    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public String getFromUserName() {
        return fromUserName;
    }

    public void setFromUserName(String fromUserName) {
        this.fromUserName = fromUserName;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }


    /**
     * 转xml
     * @return
     */
    public String toXml(){
        String xml = xStream.toXML(this);
        return xml;
    }

}
